/*
* Copyright (c) 2007 by Kirill Kolodyazhniy.
* See the file "license.terms" for information on usage and redistribution.
*/

#ifndef M_OCTREENODE_H_
#define M_OCTREENODE_H_

#include "octreescenemanager.h"

namespace Engine
{

	/**
	*   Specialized SceneNode that is customized for working within an Octree. Each node
	*   maintains its own bounding box, rather than merging it with all the children.
	*/
	class OctreeNode : public SceneNode
	{
	public:

		/**
		*   Standard constructor
		*/
		OctreeNode(OctreeSceneManager* creator, const std::string& name );

		/**
		*   Destructor.
		*/
		~OctreeNode();

		/**
		*   Returns the Octree in which this OctreeNode resides
		*/
		Octree* GetOctant()	{return m_octant;}

		/**
		*   Sets the Octree in which this OctreeNode resides
		*/
		void SetOctant( Octree* o ){m_octant = o;}

		/**
		*   Determines if the center of this node is within the given box
		*/
		bool IsIn( const AABB& box );

		/**
		*   Create new child node.
		*/
		virtual SceneNodePtr CreateChild(const std::string& name);

		/**
		*   Add attached object to render queue.
		*/
		void AddToRenderQueue(const Camera* camera, RenderQueue* renderqueue, RenderQueue* shadowsQueue, const std::vector<LightPtr>& lightList,Visibility vis);

	private:

		/**
		*  Internal method for updating the bounds for this OctreeNode.
		*/
		virtual void UpdateBounds( void );

	private:

		Octree* m_octant; ///< Octree this node is attached to.

		OctreeSceneManager* m_creator;
	};

}

#endif
